﻿using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Mvc;
using NM.Module.Cust.API.Commands.ChangePassword;
using NM.Module.Cust.API.Commands.Create;
using NM.Module.Cust.API.Commands.Delete;
using NM.Module.Cust.API.Commands.ResetPassword;
using NM.Module.Cust.API.Commands.Update;
using NM.Module.Cust.API.DTOs;
using NM.Module.Cust.API.Queries.PaginationQuery;
using System.ComponentModel;

namespace NM.Module.Cust.API.Controllers;

/// <summary>
/// 用户管理
/// </summary>
public class CustomerController : BaseModuleController
{
    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [HttpPost("Pagination")]
    [Description("分页查询")]
    public async Task<Result<PaginatedData<CustomerOutput>>> PaginationQuery(CustomersWithPaginationQuery query)
    {
        return await Result<PaginatedData<CustomerOutput>>.SucceedAsync(await Mediator.Send(query));
    }

    /// <summary>
    /// 创建用户
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Create")]
    [Description("创建用户")]
    public async Task<Result<long>> Create(CreateCustomerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 修改用户
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Update")]
    [Description("修改用户")]
    public async Task<Result<long>> Update(UpdateCustomerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 删除用户
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Delete")]
    [Description("删除用户")]
    public async Task<Result<bool>> Delete(DeleteCustomerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("ChangePassword")]
    [Description("修改密码")]
    public async Task<Result<long>> ChangePassword(ChangePasswordCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 重置密码
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("ResetPassword")]
    [Description("修改密码")]
    public async Task<Result<long>> ResetPassword(ResetPasswordCommand command)
    {
        return await Mediator.Send(command);
    }
}
